const Koa = require('koa')
const Router = require('koa-router')
const static = require('koa-static') // 获取本地静态资源
// const cors = require('@koa/cors')
const {exec}=require('./db/app')
const jwt = require('jsonwebtoken')
const parser = require('koa-bodyparser')

const app = new Koa()
const router = new Router()

// app.use(cors())

app.use(static(__dirname +'/views') )
app.use(parser())


router.post('/login' , async (ctx) =>{
    //解析参数
    const { userName , passWord } = ctx.request.body;
    const data = await exec(`select * from user where userName ='${userName}' and passWord= '${passWord}'`)
    ctx.body = "登录成功"
    console.log(data)
    // ctx.body='123'
})



app.use(router.routes())




let port = 4000
app.listen( port , ()=>{
    console.log(`http://127.0.0.1:${port}`)
})